package threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadPoolTest {
    public static void main(String[] args) {
        MyThreadFactory myThreadFactory = new MyThreadFactory("自定义-");
        //手动创建线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2,//核心线程数
                4,//最大线程数
                 10,//线程存活时间
                TimeUnit.SECONDS,//存活时间的时间单位
                new LinkedBlockingDeque<>(5),//阻塞队列
                myThreadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy());//拒绝策略
        for (int i = 0; i < 4; i++) {
            int finalI=i;
            executor.submit(()->{
                log.debug("任务一：执行目标"+finalI);
            });
            executor.submit(()->{
                log.debug("任务二：执行目标"+finalI);
            });
        }
        //终止线程
        executor.shutdown();
    }
}
